<?php
/**
 * 邮箱收件箱表
 * @author Administrator
 *
 */
class Application_Model_DbTable_Mailinbox extends Application_Model_DbTable_Base
{
    protected $_name = 'Mail_inbox';
    
    /**
     * 设置邮件属性为已读
     */
    public function setReadState()
    {
    	
    }
    
    /**
     * 根据id查看某邮件
     * @param int $id
     * @throws Exception
     */
    public function viewMailById($id){
    	$mail = $this->fetchRow(" `id`={$id} ");
		if($mail && $mailPath = $mail->maildir){
			$id = $mail->id;
			//$this->setReadState($id);
			$mailPathX = APPLICATION_PATH . "/.." . $mailPath;
			if(!file_exists($mailPathX)){
				$mailPathX = APPLICATION_PATH . "/../data" . $mailPath;
			}
			$mailPath = $mailPathX;
			if(file_exists($mailPath)){
				//$this->_helper->layout()->disableLayout();
				$mail = $mail->toArray();
				$mail["send_time"] = date("Y-m-d H:i:s",$mail["send_time"]);
				$mail = array_merge(Application_Service_Mail::viewMail($mailPath),$mail);
				return $mail;
				//print_r($this->view->mail);die();
			}else {
				throw new Exception("没有找到邮件文件 {$mailPath}，它可能已经被删除");
			}
		}else{
			throw new Exception("没有找到邮件");
		}
    }
}

